package tdtest;

import java.util.ArrayList;
import tdtest.data.*;
import tdtest.controls.ApplicationControl;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;


/**
 *
 * @author sutter
 */
public class TDTest extends Application {
	
	private TDApplication application;
	private static Stage mainStage;
	public static Stage getMainStage() { return mainStage;}
	
	@Override
	public void start(Stage stage) throws Exception {
		TDTest.mainStage = stage;
		
		createApplication();
		
		//create the layout
		GridPane grid = new GridPane();
		grid.setAlignment(Pos.TOP_LEFT);
		grid.setHgap(10);
		grid.setVgap(10);
		grid.setPadding(new Insets(25, 25, 25, 25));
		
grid.setGridLinesVisible(true);
		
		ColumnConstraints column1 = new ColumnConstraints(100,100,Double.MAX_VALUE);
		column1.setHgrow(Priority.ALWAYS);
		grid.getColumnConstraints().addAll(column1);
		
		//create the ui element for the app
		ApplicationControl appControl = new ApplicationControl(application);
		grid.add(appControl, 0, 0);
		
		//create the base scroll pane
		ScrollPane scrollPane = new ScrollPane();
		scrollPane.setContent(grid);
		
		//create the scene
		Scene scene = new Scene(scrollPane, 800, 600);
		stage.setScene(scene);
		
		//show the scene
		scene.getStylesheets().add(TDTest.class.getResource("TDTest.css").toExternalForm());
		stage.show();
	}

	/**
	 * The main() method is ignored in correctly deployed JavaFX application. main() serves only as fallback in case the application can not be launched through
	 * deployment artifacts, e.g., in IDEs with limited FX support. NetBeans ignores main().
	 *
	 * @param args the command line arguments
	 */
	public static void main(String[] args) {
		launch(args);
	}
	
	private void createApplication() {
		//create the app
		application = new TDApplication();
		application.name = "Test App";
		application.notes = "This is a test application. a;sdjfaksdjf;lakjsdf;lkajsdfk;la";
		
		//create the data structures and actions in the app
		TDGroup<TDDataStructure> dataStructureGroup;
		TDDataStructure dataStructure;
		TDGroup<TDFunction> functionGroup;
		TDFunction function;
		TDGroup<TDVariable> variableGroup;
		TDVariable variable;
		TDGroup<TDAction> actionGroup;
		TDAction action;
		TDEvent event;
		
		//data structures
		dataStructureGroup = new TDGroup<TDDataStructure>();
		dataStructureGroup.name = "Data Structure Group 1";
		dataStructureGroup.notes = "This is the first data structure group.";
		application.dataStructures.groupItems.add(dataStructureGroup);
		
		//create a data structure
		dataStructure = new TDDataStructure();
		dataStructure.name = "Data Strcuture 1";
		dataStructure.notes = "This is a test manager.";
		dataStructureGroup.groupItems.add(dataStructure);
		
		//add data structure varaibles
		variableGroup = new TDGroup<TDVariable>();
		variableGroup.name = "Public";
		variableGroup.notes = "This is the default group for public variables.";
		dataStructure.variables.groupItems.add(variableGroup);
		
		variable = new TDVariable();
		variable.name = "x";
		variable.notes = "This is the x coordinate.";
		variableGroup.groupItems.add(variable);
		
		variable = new TDVariable();
		variable.name = "y";
		variable.notes = "This is the y coordinate.";
		variableGroup.groupItems.add(variable);
		
		//add data structure functions
		functionGroup = new TDGroup<TDFunction>();
		functionGroup.name = "Public";
		functionGroup.notes = "This is the default group for public functions.";
		dataStructure.functions.groupItems.add(functionGroup);
		
		function = new TDFunction();
		function.name = "Process Data";
		function.notes = "This function processes the data.";
		functionGroup.groupItems.add(function);
		
		function = new TDFunction();
		function.name = "Transform X";
		function.notes = "This transforms the x coordinate.";
		functionGroup.groupItems.add(function);
		
		function = new TDFunction();
		function.name = "Transform Y";
		function.notes = "This transforms the y coordinate.";
		functionGroup.groupItems.add(function);
		
		//data structures
		actionGroup = new TDGroup<TDAction>();
		actionGroup.name = "Action Group 1";
		actionGroup.notes = "This is the first action group.";
		application.actions.groupItems.add(actionGroup);
		
		//create a data structure
		action = new TDAction();
		action.name = "Run Action";
		action.notes = "This is the actino that starts the program.";
		actionGroup.groupItems.add(action);

		action = new TDAction();
		action.name = "Mouse Click Action";
		action.notes = "This is the mouse click action";
		actionGroup.groupItems.add(action);

		
		action = new TDAction();
		action.name = "Mouse Move Action";
		action.notes = "This is the mouse move action";
		actionGroup.groupItems.add(action);
	}
}
